package cn.chrilwe.pigpig.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.chrilwe.pigpig.core.base.BaseController;
import cn.chrilwe.pigpig.core.model.user.Authority;
import cn.chrilwe.pigpig.core.response.BaseResult;
import cn.chrilwe.pigpig.user.common.ResponseEnum;
import cn.chrilwe.pigpig.user.request.JoinRolePermissionRequest;
import cn.chrilwe.pigpig.user.service.PermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
  * 权限管理
 * @author chrilwe
 * 2020-9-3
 */
@RestController
@RequestMapping("/permission")
@Api(tags = "权限管理接口")
public class PermissionManagerController extends BaseController {
	
	@Autowired
	private PermissionService permissionService;
	
	@PostMapping("/add")
	@ApiOperation("管理员新增权限信息")
	public BaseResult addPermission(@RequestBody Authority authority) {
		
		return permissionService.addPermission(authority);
	}
	
	
	@PostMapping("/join")
	@ApiOperation("管理员管理角色权限")
	public BaseResult joinRolePermission(@RequestBody JoinRolePermissionRequest request) {
		
		return permissionService.roleJoinPermission(request);
	}
	
	@GetMapping("/deleteById")
	public BaseResult deletePermissionById(@RequestParam("authId")int authId) {
		permissionService.deletePermissionById(authId);
		return new BaseResult(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getName());
	}
}
